package com.sherllinhe.member.controller;

import com.sherllinhe.common.resp.CommonResp;
import com.sherllinhe.member.mapper.MemberMapper;
import com.sherllinhe.member.req.MemberLoginReq;
import com.sherllinhe.member.req.MemberRegisterReq;
import com.sherllinhe.member.req.MemberSendCodeReq;
import com.sherllinhe.member.resp.MemberLoginResp;
import com.sherllinhe.member.service.MemberService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * 功能：
 * 作者：Sherllin He
 * 日期：2025/4/25 21:10
 */
@RequestMapping("/member")
@RestController
public class MemberController {
    @Autowired
    private MemberService memberService;

    @GetMapping("/count")
    public CommonResp<Integer> count(){
        Integer count = memberService.count();
        return new CommonResp<>(count);
    }

    @PostMapping("/register")
    public CommonResp<Long> register(@Valid  MemberRegisterReq req){
        long id = memberService.register(req);
        return new CommonResp<>(id);
    }
    @PostMapping("/send-code")
    public CommonResp<Long> sendCode(@Valid @RequestBody MemberSendCodeReq req){
        memberService.sendCode(req);
        return new CommonResp<>();
    }

    @PostMapping("/login")
    public CommonResp<MemberLoginResp> login(@Valid @RequestBody MemberLoginReq req){
        MemberLoginResp resp = memberService.login(req);
        return new CommonResp<>(resp);
    }

}
